package cn.wenlihelp.service.task.impl;

import cn.wenlihelp.bean.Task;
import cn.wenlihelp.bean.Taskinfo;
import cn.wenlihelp.mapper.TaskMapper;
import cn.wenlihelp.mapper.TaskinfoMapper;
import cn.wenlihelp.service.task.TaskService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TaskServiceImpl implements TaskService {
    @Resource
    private TaskMapper taskMapper;
    @Resource
    private TaskinfoMapper taskinfoMapper;

    @Override
    public PageInfo<Task> findAll(int page, int limit, Task task) {
        PageHelper.startPage(page,limit);
        System.out.println(task);
        List<Task> all = taskMapper.findAll(task);
        System.out.println(all);
        return new PageInfo<>(all);
    }

    @Override
    public Task findById(Long id) {
        return taskMapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean update(Taskinfo taskinfo) {
        return taskinfoMapper.update(taskinfo);
    }

    @Override
    public boolean add(Task task) {
        if (taskMapper.insert(task)){
            return taskinfoMapper.insert(task.getTaskinfo());
        }
        return false;
    }

    @Override
    public boolean del(Integer[] ids) {
        if (taskMapper.del(ids)){
            return taskMapper.del(ids);
        }
        return false;
    }

    public boolean accept(Integer taskId,Integer accountId){
        return taskMapper.addContact(taskId,accountId);
    }
}
